#!/bin/bash

function exittrap()
{
	exit
}
trap exittrap INT

if [ $# -lt 3 ]; then
	echo "Usage: svnrepogrep.sh path_to_repo filename_pattern content_pattern [start_rev_no [end_rev_no]] 2>/dev/null"
	echo "  filename_pattern and content_pattern should be in PHP's preg_match format, e.g.: \"/xml/\""
	exit
fi


current=`cat $1db/current | grep -h -o "[0-9]*"`

start=0
if [ $# -ge 4 ]; then
	start=$4
fi

end=$current
if [ $# -ge 5 ]; then
        end=$5
fi


i=$start
echo "Checking revisions:" $start "to" $end
while [ $i -le $end ]
do
	svnadmin dump $1 -r $i 2>/dev/null | php svnrepogrep.php $2 $3
	if [ $? != 0 ]; then
		exit $?
	fi
	let i++
done

